﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQuery Samples</title>
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
</head>
<body onload="sendMSG()">
    <input type="button" value="Send a Message" />
    <a href="javascript:;"><span id="btnSendSms">发送代金券到手机</span></a>
</body>
<script type="text/javascript">
    var btnSendSMS = $('#btnSendSms');
    var wait = 5;
    var sendMSG = function () {
        alert('clicked');
        setTimeout(time(btnSendSMS), 1000);
    };

    function time(o) {
        if (wait == 0) {
            btnSendSMS.one('click', sendMSG);

            //o.removeAttr("disabled");
            btnSendSMS.html("发送代金券到手机");
            //o.attr("value", "Send a message to your phone");
            wait = 5;
        } else {
            btnSendSMS.unbind('click', sendMSG);
            /*o.css({ background-color: "red" });*/
            //o.attr("disabled", "true");
            btnSendSMS.html("【" + wait + "】秒后重新发送");
            wait--;
            setTimeout(function () { time(o); }, 1000);
        }
    }

    btnSendSMS.one('click', sendMSG);
    //btnSendSMS.click(function() { setTimeout(time(btnSendSMS), 1000); });
</script>
</html>
